/*
 * RulesAPI - The interface by which game clients communicate to the
 * gameplay.
 *
 * Copyright 2008 James W. Hofmann
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

package rules;

class RulesAPI
{

	public static var g : rules.Game;

	public static var amrecording : Bool;
	
	public static var record : List<GameMessage>;
	
	public static function startgame(?seed : Int,
									 ?amrecording : Bool) : 
		Array<GameResponse>
	{
		GameResponse.startcomposition();
		g = new Game(seed);
		if (amrecording)
		{
			RulesAPI.amrecording = true;
			record = new List();
		}
		else
			RulesAPI.amrecording = false;
		return GameResponse.composition;
	}
	
	public static function message(msg : Array<GameMessage>) 
	: Array<GameResponse>
	{

		
		GameResponse.startcomposition();

		if (amrecording)
		{
			for (n in msg)
			{
				n._parse();
				record.add(n); 
				// this order won't add messages that throw exceptions
			}
		}
		else
		{
			for (n in msg)
			{
				n._parse();
			}
		}
		
		return GameResponse.composition;
	}

}
